#!/usr/bin/env python3
"""
修复视频分段数量限制问题
"""

import asyncio
from pathlib import Path
from app.services.video_splitter import VideoSplitter

async def test_segment_limits():
    """测试不同的分段限制"""
    
    video_path = Path("uploads/24e6864f-95e0-4ae5-9406-ad9b8d66b567.mp4")
    
    if not video_path.exists():
        print(f"❌ 视频文件不存在: {video_path}")
        return
    
    splitter = VideoSplitter()
    
    # 获取视频信息
    video_info = await splitter._get_video_info(video_path)
    total_duration = video_info['duration']
    
    print(f"📹 视频信息:")
    print(f"   文件: {video_path.name}")
    print(f"   总时长: {total_duration:.1f}秒 ({total_duration/60:.1f}分钟)")
    
    # 测试不同的最大分段数
    test_limits = [20, 30, 40, 50]
    
    for max_segments in test_limits:
        print(f"\n🧪 测试最大分段数: {max_segments}")
        
        # 计算理论分段数
        theoretical_segments = int(total_duration / 60) + 1
        print(f"   理论分段数 (60秒/段): {theoretical_segments}")
        
        # 实际测试拆分
        try:
            result = await splitter.split_video_by_duration(
                video_path, 
                segment_duration=60,
                max_segments=max_segments,
                min_segment_duration=10
            )
            
            segments_count = len(result.get('segments', []))
            print(f"   实际生成分段数: {segments_count}")
            print(f"   拆分状态: {'✅ 成功' if segments_count > 0 else '❌ 失败'}")
            
            if segments_count > 0:
                print(f"   建议使用最大分段数: {max_segments}")
                break
                
        except Exception as e:
            print(f"   ❌ 拆分失败: {e}")

if __name__ == "__main__":
    asyncio.run(test_segment_limits())